<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
class helpfunc {
/*********************BEGIN LIST FUNCTION*************************/
function check_extent_file($file_type)
{
	$extent_file = array("image/jpeg","image/png","image/png");
	return (in_array($file_type,$extent_file));
	
}
function copy_and_change_filename($file_input_tmp, $file_input_name,$dir_upload, $prefix)
{
	$source = $file_input_tmp;
	$part=explode(".", $file_input_name);
	$file_name = $prefix.'_'.time().'_'.$part[0] . "." . $part[1];
	$dest = $dir_upload . $file_name;
	move_uploaded_file( $source, $dest );
	return $file_name;
}
function copy_and_resize($originalName,$dirUpload,$dirFix,$widthSize,$heightSize)
{
	$original = $dirUpload . $originalName;
	$fix = $dirFix . $originalName;
	list($width,$height,$type) = getimagesize($original) ;
	if($width <= $widthSize && $height <= $heightSize)
	{
		$ChoiceWith = $width;
		$ChoiceHeight = $height;
	}else{
		if($width > $height && $width > $widthSize)
		{
			$radioWidth = $widthSize/$width;
			$ChoiceWith = $radioWidth * $width;
			$ChoiceHeight = $radioWidth * $height;
		}
		if($width > $height && $width < $widthSize)
		{
			$ChoiceWith = $width;
			$ChoiceHeight = $height;
		}
		if($height > $width && $height > $heightSize)
		{
			$radioHeight = $heightSize/$height;
			$ChoiceWith = $radioHeight * $width;
			$ChoiceHeight = $radioHeight * $height;
		}
		if($height > $width && $height < $heightSize)
		{
			$ChoiceWith = $width;
			$ChoiceHeight = $height;
		}
	}
	if($width == $height)
	{
		$radioWidth = $widthSize/$width;
		$ChoiceWith = $radioWidth * $width;
		$ChoiceHeight = $radioWidth * $height;
	}
	if($type == 2)
	{
		//@header("Content-type: image/jpeg");
		$tn = imagecreatetruecolor($ChoiceWith, $ChoiceHeight) ;
		$image = imagecreatefromjpeg($original) ;
		imagecopyresampled($tn, $image, 0, 0, 0, 0, $ChoiceWith,$ChoiceHeight, $width, $height) ;
		imagejpeg($tn, $fix, 100) ;
	}
	if($type == 1)
	{
		//@header("Content-type: image/gif");
		$tn = imagecreatetruecolor($ChoiceWith, $ChoiceHeight) ;
		$image = imagecreatefromgif($original) ;
		imagecopyresampled($tn, $image, 0, 0, 0, 0, $ChoiceWith,$ChoiceHeight, $width, $height) ;
		imagegif($tn, $fix) ;
	}
	if($type == 3)
	{
		//@header("Content-type: image/png");
		$tn = imagecreatetruecolor($ChoiceWith, $ChoiceHeight) ;
		$image = imagecreatefrompng($original) ;
		imagecopyresampled($tn, $image, 0, 0, 0, 0, $ChoiceWith,$ChoiceHeight, $width, $height) ;
		imagepng($tn, $fix, 100) ;
	}
}

/*********************END LIST FUNCTION*************************/
}
?>